package com.imooc;

import com.imooc.controller.intercept.MiniInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 修改了,拉取，修改
 * @author Zhou
 * @create 2020-11-17 10:04
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    /**
     * 用来配置加载静态文件
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/META-INF/resources/")
                .addResourceLocations("file:D:/programming/imooc_video_dev/");
    }

    @Bean(initMethod = "init")
    public ZKCuratorClient zkCuratorClient(){
        return new ZKCuratorClient();
    }

    /**
     * 自定义拦截器
     * @return
     */
    @Bean
    public MiniInterceptor miniInterceptor(){
        return new MiniInterceptor();
    }

    /**
     * 拦截器注册
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(miniInterceptor()).addPathPatterns("/user/**")
                                                  .excludePathPatterns("/user/queryPublisher")
                                                  .addPathPatterns("/video/upload", "/video/uploadCover")
                                                  .addPathPatterns("/video/userLike","/video/userUnlike")
                                                  .addPathPatterns("/video/saveComment")
                                                  .addPathPatterns("/bgm/**");
        super.addInterceptors(registry);
    }

}
